home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / awe2-0_1.lha / awe2-0.1 / Src / RCS / CpuMultiplexor.h,v < prev    next >
Text File  |  1989-03-22  |  6KB  |  309 lines

  1. head     3.3;
  2. branch   ;
  3. access   ;
  4. symbols  ;
  5. locks    grunwald:3.3; strict;
  6. comment  @ * @;
  7.  
  8.  
  9. 3.3
  10. date     89.03.22.22.13.14;  author grunwald;  state Exp;
  11. branches ;
  12. next     3.2;
  13.  
  14. 3.2
  15. date     89.02.20.15.34.01;  author grunwald;  state Exp;
  16. branches ;
  17. next     3.1;
  18.  
  19. 3.1
  20. date     88.12.20.13.49.36;  author grunwald;  state Exp;
  21. branches ;
  22. next     1.2;
  23.  
  24. 1.2
  25. date     88.11.02.13.40.15;  author grunwald;  state Exp;
  26. branches ;
  27. next     1.1;
  28.  
  29. 1.1
  30. date     88.10.30.13.05.36;  author grunwald;  state Exp;
  31. branches ;
  32. next     ;
  33.  
  34.  
  35. desc
  36. @@
  37.  
  38.  
  39. 3.3
  40. log
  41. @before subclass
  42. @
  43. text
  44. @// This may look like C code, but it is really -*- C++ -*-
  45. // 
  46. // Copyright (C) 1988 University of Illinois, Urbana, Illinois
  47. //
  48. // written by Dirk Grunwald (grunwald@@cs.uiuc.edu)
  49. //
  50. #ifndef CpuMultiplexor_h
  51. #define CpuMultiplexor_h
  52.  
  53. #include <Config.h>
  54. #include <HardwareContext.h>
  55. #include <CpuMuxExceptions.h>
  56. #include <SpinLock.h>
  57.  
  58. //
  59. //    Define the abstractions for per UNIX process resources.
  60. //
  61.  
  62. #include <ThreadContainer.h>
  63.  
  64. class Thread;
  65. class ReserveByException;
  66. class AwesimeHeap;
  67. class SpinLock;
  68. class SpinFetchAndOp;
  69. class CpuMultiplexor;
  70.  
  71. //
  72. //    Filled in by the single original UNIX process. This value may
  73. //    change during execution
  74. //
  75.  
  76. extern int CpuMultiplexors;
  77. extern CpuMultiplexor *ThisCpu;
  78. extern int CpuMuxDebugFlag;
  79.  
  80. extern SpinLock CpuCerrLock;
  81.  
  82. class CpuMultiplexor {
  83. protected:
  84.     Thread *currentThread;
  85.     HardwareContext systemContext;
  86.  
  87.     ThreadContainer *myCurrentEvents;
  88.     SpinLock *myCurrentEventsLock;
  89.     int *myCurrentEventsCounter;
  90.  
  91.     SpinFetchAndOp *globalCurrentEventsCounter;
  92.  
  93.     int iYam;    // I yam what I yam
  94.     int pid;    // ...except to UNIX
  95.  
  96.     int oldGeneration; // placed here to avoid optimizer screwups
  97.  
  98.     char nameSpace[128];
  99.     char *pNameTemplate;
  100.     char *pName;
  101.  
  102.     int *terminated;
  103.     int enabled;
  104.  
  105.     Thread *remove();
  106.     //
  107.     // Constructors of this class and all subclasses should call their
  108.     // own allocateLocalEventStructures, because constructors automatically
  109.     // chain the calls.
  110.     //
  111.     // Use AllocateEventStructures when allocating resources for a CPU and
  112.     // you're not in the constructor. Use deallocateEventStructures for
  113.     // removing those resources. These routines should call subclass
  114.     // instances of the same names.
  115.     //
  116.     void allocateLocalEventStructures(int,int);
  117.     virtual void allocateEventStructures(int,int);
  118.     virtual void deallocateEventStructures();
  119.  
  120.     //
  121.     // Primarily provided so subclasses, e.g. SimulationMultiplexor,
  122.     // can efficiently add threads without a lot of locking.
  123.     //
  124.     void addUnlocked(Thread *);
  125.     void addToAnother(int, Thread *);
  126.  
  127.     //
  128.     //    Exception handlers.
  129.     //
  130.  
  131.     friend class ExceptionReserve;
  132.     friend class ExceptionTerminate;
  133.     friend class ExceptionReschedule;
  134.     friend class ExceptionIveSuspended;
  135.     friend class ExceptionEnrollDismissCpu;
  136.  
  137.     ExceptionClass *raisedBy;
  138.     ExceptionReserve reserveException;
  139.     ExceptionTerminate terminateException;
  140.     ExceptionReschedule rescheduleException;
  141.     ExceptionIveSuspended iveSuspendedException;
  142.     ExceptionEnrollDismissCpu enrollDismissCpuException;
  143.  
  144.  
  145. //
  146. //    Public interfaces for exceptions
  147. //
  148. public:
  149.  
  150.     void raise(ExceptionClass *);
  151.     void reserveByException( ReserveByException * );
  152.     void threadTerminateException( void ** );
  153.     void flick();
  154.  
  155. public:
  156.     CpuMultiplexor(int debug = 0);
  157.     virtual ~CpuMultiplexor();
  158.  
  159.     virtual void fireItUp(int Cpus = 1, unsigned shared = (4196 * 500));
  160.     virtual void warmThePot(int);
  161.     virtual void stirItAround();
  162.     virtual void coolItDown();
  163.  
  164.     virtual void terminateAll();
  165.     virtual void enrollCpu();
  166.     virtual void dismissCpu();
  167.  
  168.     virtual void add(Thread *);
  169.  
  170.     Thread * CurrentThread();
  171.  
  172.     void debug(int newdebug);
  173.     int debug();
  174.     char *name();
  175.  
  176.     int cpuId();
  177. };
  178.  
  179.  
  180.  
  181. inline int CpuMultiplexor::cpuId()
  182. {
  183.     return( iYam );
  184. }
  185.  
  186. inline char *
  187. CpuMultiplexor::name()
  188. {
  189.     return(pName);
  190. }
  191.  
  192.  
  193. inline Thread *
  194. CpuMultiplexor::CurrentThread()
  195. {
  196.     return( currentThread );
  197. }
  198.  
  199. inline void
  200. CpuMultiplexor::addUnlocked(Thread *who)
  201. {
  202.     //
  203.     // Add them to the list of current events
  204.     //
  205.     myCurrentEvents -> add( who );
  206. }
  207.  
  208. //
  209. //    Expansions for exception handling
  210. //
  211.  
  212. #include <Thread.h>
  213. inline void
  214. CpuMultiplexor::reserveByException( ReserveByException *sem )
  215. {
  216.     reserveException.reserve(sem);
  217.     raise( &reserveException );
  218. }
  219.  
  220. inline void
  221. CpuMultiplexor::threadTerminateException( void **killMe )
  222. {
  223.     terminateException.terminate( killMe );
  224.     raise( &terminateException );
  225. }
  226.  
  227. inline void
  228. CpuMultiplexor::flick()
  229. {
  230.     rescheduleException.cpu(-1);
  231.     currentThread -> cpuAffinity = -1;
  232.     raise( &rescheduleException ); 
  233. }
  234.  
  235. inline Thread *
  236. CurrentThread()
  237. {
  238.     return( ThisCpu -> CurrentThread() );
  239. }
  240.  
  241. inline void
  242. CheckCurrentStack()
  243. {
  244.     CurrentThread() -> checkStack();
  245. }
  246.  
  247. //
  248. //    These are things the user needs to define
  249. //
  250.  
  251. extern ThreadContainer *AllocateHardwareCurrentEventsStructure();
  252.  
  253. #endif /* CpuMultiplexor_h */
  254. @
  255.  
  256.  
  257. 3.2
  258. log
  259. @Start using Gnu library heaps for schedulers
  260. @
  261. text
  262. @d10 4
  263. a13 4
  264. #include "Config.h"
  265. #include "HardwareContext.h"
  266. #include "CpuMuxExceptions.h"
  267. #include "SpinLock.h"
  268. d19 1
  269. a19 1
  270. #include "ThreadContainer.h"
  271. d169 1
  272. a169 1
  273. #include "Thread.h"
  274. d196 6
  275. @
  276.  
  277.  
  278. 3.1
  279. log
  280. @Steay version
  281. @
  282. text
  283. @@
  284.  
  285.  
  286. 1.2
  287. log
  288. @Before using SpinEvents for global coordination
  289. @
  290. text
  291. @d56 1
  292. d63 12
  293. a74 1
  294.     virtual void allocateEventStructures(int);
  295. d76 5
  296. d92 1
  297. d99 1
  298. d188 1
  299. @
  300.  
  301.  
  302. 1.1
  303. log
  304. @Initial revision
  305. @
  306. text
  307. @d53 2
  308. @
  309.